import { ${entity}Type } from '@/datatypes/${entity}/data';
import { ProFormText, StepsForm } from '@ant-design/pro-components';
import { Modal } from 'antd';
import React from 'react';

export type FormValueType = {
  target?: string;
  template?: string;
  type?: string;
  time?: string;
  frequency?: string;
} & Partial<${entity}Type>;

export type UpdateFormProps = {
  onCancel: (flag?: boolean, formVals?: FormValueType) => void;
  onSubmit: (values: FormValueType) => Promise<void>;
  updateModalVisible: boolean;
  values: Partial<${entity}Type>;
};

const UpdateForm: React.FC<UpdateFormProps> = (props) => {
  return (
    <StepsForm
      stepsProps={{
        size: 'small',
      }}
      stepsFormRender={(dom, submitter) => {
        return (
          <Modal
            width={640}
            style={{
              padding: '32px 40px 48px',
            }}
            destroyOnClose
            title="更新"
            open={props.updateModalVisible}
            footer={submitter}
            onCancel={() => {
              props.onCancel();
            }}
          >
            {dom}
          </Modal>
        );
      }}
      onFinish={props.onSubmit}
    >
      <StepsForm.StepForm
        initialValues={{
<#list table.fields as field>
  <#if
          field.comment!?length gt 0
          && field.name !="id"
          && field.name !="create_time"
          && field.name !="modify_time"
          && field.name !="is_delete"
          && field.name !="creator"
          && field.name !="updater"
          && field.name !="tenant_id"
          && field.name !="version" >
    ${field.propertyName}: props.values.${field.propertyName},
  </#if>
</#list>
        }}
        title="基本信息"
      >
<#list table.fields as field>
  <#if
          field.comment!?length gt 0
          && field.name !="id"
          && field.name !="create_time"
          && field.name !="modify_time"
          && field.name !="is_delete"
          && field.name !="creator"
          && field.name !="updater"
          && field.name !="tenant_id"
          && field.name !="version" >
        <ProFormText
             rules={[
               {
                 required: true,
                 message: '${field.comment}为必填项',
              },
            ]}
            width="md"
            name="${field.propertyName}"
            label={'${field.comment}'}
            placeholder={'请输入${field.comment}'}
         />
  </#if>
</#list>
      </StepsForm.StepForm>
    </StepsForm>
  );
};

export default UpdateForm;
